package com.fenghuajueli.module_user.network.retrofit

import com.fenghuajueli.libbasecoreui.constants.AppConfigInfo
import com.fenghuajueli.module_user.network.di.RetrofitDiModule
import com.fenghuajueli.module_user.network.model.helpcenter.NetworkHelpCenter
import com.fenghuajueli.module_user.network.model.NetworkUserResponse
import com.fenghuajueli.module_user.network.model.refund.NetworkRefund
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import okhttp3.MediaType.Companion.toMediaType
import retrofit2.Retrofit
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Path
import retrofit2.http.Query


//用户系统请求接口
private interface UserApi {

    //https://scbgbm-iq.shicibox.cn/api/v1_test/cms/helpCenter?page=1&page_size=20&type=1
    @GET(value = "api/{environment}/cms/helpCenter")
    suspend fun getHelpCenter(
        @Path("environment") environment: String,
        @Query("page") page: Int,
        @Query("page_size") pageSize: Int,
        @Query("type") type: Int,
    ): NetworkUserResponse<NetworkHelpCenter>

    @GET(value = "api/{environment}/order/user-refund")
    suspend fun getRefundResult(
        @Path("environment") environment: String,
        @Header("token") token: String,
    ): NetworkUserResponse<NetworkRefund>
}

object UserNetwork {
    private val networkApi = Retrofit.Builder()
        .baseUrl("https://${AppConfigInfo.HTTP_HOST}")
        .callFactory(RetrofitDiModule.okHttpCallFactory())
        .addConverterFactory(
            RetrofitDiModule.providesNetworkJson()
                .asConverterFactory("application/json".toMediaType()),
        )
        .build()
        .create(UserApi::class.java)

    suspend fun getHelpCenter(type: Int): NetworkUserResponse<NetworkHelpCenter> =
        networkApi.getHelpCenter(
            if (AppConfigInfo.APP_DEBUG) "v1_test" else "v1", 1, 50, type)

    suspend fun getRefundResult(token: String): NetworkUserResponse<NetworkRefund> =
        networkApi.getRefundResult(
            if (AppConfigInfo.APP_DEBUG) "v1_test" else "v1", token)
}